import lejos.nxt.*;

public class AudioAlert implements Runnable {
	private Thread t;

	public void run() {
		while (true) {
			Sound.playTone(500, 500);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				break;
			}
			Sound.playTone(800, 500);
		}
	}

	public void enableSound() {
		if (t == null) {
			t = new Thread(this);
			t.setDaemon(true);
			t.start();
		}
	}

	public void disableSound() {
		if (t != null) {
			t.interrupt();
			t = null;
		}
	}
}
